package jsen.tool.ddd.demo.domain.parking.spec.car;

import jsen.tool.ddd.adapter.infrastructure.specification.base.CompositeSpecification;
import jsen.tool.ddd.adapter.infrastructure.specification.base.SpecContext;
import jsen.tool.ddd.demo.domain.base.Ds;
import jsen.tool.ddd.demo.domain.parking.Car;

/**
 * @author jsen
 * @date 2021/10/6
 */
public class CarPlateSpec extends CompositeSpecification<Car> {
    @Override
    public boolean isSatisfiedBy(SpecContext<Car> t) {
        Car car = t.getData();
        if (car.getPlate() == null || car.getPlate().length() < 5) {
            t.addError("carPlate", "车牌不合法");
            return false;
        }
        if (Ds.existPlate(car.getPlate())) {
            t.addError("carPlate", "牌照已存在");
            return false;
        }
        return true;
    }
}
